@extends('layouts.back_stage')
@section('content')
    <script src="{{env('CDN_DOMAIN_NAME')}}/js/commonjs/jquery.select.js"></script>
    <script src="{{env('CDN_DOMAIN_NAME')}}/js/commonjs/jquery.page.js?v=1.0.4"></script>
    <style>
        .form_ul{width:100%;height:30px;margin-bottom:20px;}
        .form_li{width:210px;line-height:30px;margin-right:10px;float:left;font-size:14px;}
        .form_inp{width:130px;height:30px;line-height:30px;font-size:14px;float:right;outline:none;border:1px solid #cfdada;background:#fff;border-radius:2px;padding:6px 12px;color:#555;box-shadow: none;}
        .sel_inp{width:130px;height:30px;line-height:30px;font-size:14px;float:right;outline:none;border:1px solid #cfdada;background:#fff;border-radius:2px;padding:4px 8px;color:#555;box-shadow: none;}
        .fabric_div1{width:100%;}
        .tab1{border-collapse:collapse;width:100%;font-size:14px;color:#383838;background:#fff;margin-bottom:10px;}
        table td{text-align:center;height:35px;}
        table,th,td{border:1px solid #ccc;}
        .oneTb{width:100%;overflow-x:scroll;overflow-y:hidden;}
        ::-webkit-scrollbar{width:5px;height:5px;}
        .tab1 .form_inp,.tab1 .sel_inp{width:100%;height:100%;outline:none;background:#fff;border:none;padding:0;cursor:pointer;text-align:center;}
        /*遮罩层*/
        .mask{position:fixed;top:0;right:0;left:0;bottom:0;z-index:10000;background:#000;opacity:0.8;filter:alpha(opacity=80);-moz-user-select: none; -webkit-user-select: none;}
        /*弹框1*/
        .info_box{position:absolute;top:25%;left:30%;width:800px;height:auto;overflow:hidden;background:#fff;z-index:99999;padding:15px;display:none;}
        .chaL{position:absolute;top:-3px;right:0;color:red;font-size:20px;cursor:pointer;}
        .gong{width:100%;}
        .gong tbody tr:hover{background:#27c24c;cursor:pointer;color:#fff;}
        .shuoM{appearance:none;-moz-appearance:none;-webkit-appearance:none;text-indent:10px;}
        .tab1 .shuoM,.tab1 .guiGe,.tab1 .xiaoL,.tab1 .danW,.tab1 .Cshu{background:#F5F5F5;cursor:default;}
        .tab1 .bgCshu{background:#fff;cursor:pointer;}
        .save_add{margin-top:30px;margin-left:50%;}
        /*弹框2*/
        .boxJxd{position:fixed;top:20%;left:20%;width:1000px;height:auto;overflow:hidden;background:#fff;z-index:99999;padding:15px;display:none;}
        .yinClose{position:absolute;top:-3px;right:0;color:red;font-size:20px;cursor:pointer;}
        .seek_p{width:100%;margin:0 auto;padding-top:10px;}
        .seek_lab{width:185px;line-height:30px;margin-right:10px;}
        .seek_sel{width:130px;height: 30px;line-height:30px;float:right;outline:none;font-size: 13px;padding:5px 10px;font-weight: normal;border-radius: 2px;color: #555;background:#fff;background-image: none;border: 1px solid #cfdadd;box-shadow: none;}
        .bt_del{text-align: center;display:inline-block;}
        .fabric-choose{width:100%;line-height:30px;height:30px;margin:20px auto;}
        .fabric_div2{width:100%;}
        .fabric_div3{width:100%;margin-top:30px;}
        .tab2,.tab3{border-collapse:collapse;width:100%;font-size:14px;color:#383838;background:#fff;margin-bottom:10px;}
        .twoTb{width:100%;}
        .threeTb{width:100%;overflow-y:hidden;}
        .two_tr{cursor:pointer;}
        .two_tr.in{background:#27c24c;color:#fff;}
        .colr{color:red;}
    </style>
    <script>
        //供应商
        var suppliers = [
            <?php $j = count($suppliers_arr);$i = 0; ?>
                    @foreach ($suppliers_arr as $k=>$v )'{{$v["name"]}}'<?php $i++;?> @if($i<$j),@endif
            @endforeach
        ];
    </script>
    <div class="container">
        <div class="row">
            <div style="margin:30px;"><h3 >添加面辅料采购入库<span style="color:red;font-size:14px;">(先引单再添加)</span></h3></div>
            <div style="width:95%;margin-left:40px;">
                <div class="form-group">
                    <h3 style="float:left;margin-right:20px;">基本信息</h3>
                    <a class="btn btn-primary yinDan" href="javascript:;" abc="{{$pst_infos->notice_id}}">引单</a>
                </div>
                <div class="form-group">
                    <ul class="form_ul">
                        <li class="form_li" style="width:330px;">供应商加工厂：<input id="colorInput0" class="form_inp supplier_name" value="{{$pst_infos->supplier_name}}" type="text" autocomplete="off" autocorrect="off" placeholder="供应商" style="width:220px;"  /></li>
                        <li class="form_li">销售季节：
                            <select class="sel_inp quarter">
                                <option value="">请选择</option>
                                @if(count($season))
                                    @foreach($season as $k => $v)
                                        <option value="{{$v}}" @if(isset($pst_infos->sale_quarter) && $pst_infos->sale_quarter==$v) selected @endif>{{$v}}</option>
                                    @endforeach
                                @endif
                            </select>
                        </li>
                        <li class="form_li">入库仓库：
                            <select class="sel_inp warehouse">
                                @if($pst_infos->warehouse=='公司面料仓库')
                                    <option value="公司面料仓库">公司面料仓库</option>
                                @elseif($pst_infos->warehouse=='公司辅料仓库')
                                    <option value="公司辅料仓库">公司辅料仓库</option>
                                @endif
                                <option value="">请选择</option>
                                <option value="公司面料仓库">公司面料仓库</option>
                                <option value="公司辅料仓库">公司辅料仓库</option>
                            </select>
                        </li>
                    </ul>
                    <ul class="form_ul">
                        <li class="form_li" style="width:330px;">摆放位置：<input style="width:220px;" class="form_inp place_r" value="{{$pst_infos->position}}" type="text" autocomplete="off" autocorrect="off" placeholder="摆放位置"  /></li>
                        <li class="form_li" style="width: 209px;">单据号：<input disabled class="form_inp plan_num" value="{{$pst_infos->storage_num}}" type="text"  /></li>
                    </ul>
                    <ul class="form_ul">
                        <li class="form_li" style="width:770px;">备注：<input style="width:660px;"class="form_inp remark" value="{{$pst_infos->remark}}" type="text" autocomplete="off" autocorrect="off" placeholder="备注"  /></li>
                    </ul>
                </div>
                <div class="form-group">
                    <a class="btn btn-primary addIns" href="javascript:;">添加</a>
                </div>
                <div class="form-group oneTb">
                    <div class="fabric_div1">
                        <table class="tab1">
                            <thead>
                            <tr>
                                <td style="min-width:70px;">类型</td>
                                <td>厂家货号</td>
                                <td style="min-width:80px;">面辅料颜色</td>
                                <td style="min-width:80px;background:#f5f5f5;">颜色说明</td>
                                <td style="background:#f5f5f5;">小类</td>
                                <td style="background:#f5f5f5;">面辅料规格</td>
                                <td style="background:#f5f5f5;">采购数量</td>
                                <td>入库数量</td>
                                <td>单价</td>
                                <td>金额</td>
                                <td style="background:#f5f5f5;">单位</td>
                                <td style="width:45px;">操作</td>
                            </tr>
                            </thead>
                            <tbody>
                            @if(count($pst_child_infos))
                                @foreach($pst_child_infos as $k => $v)
                                    @if($v['notice_details_id']>0)
                                        <tr class="tr{{$v['notice_details_id']}}" ids="{{$v['notice_details_id']}}">
                                    @else
                                        <tr class="newInfos" ids="0">
                                            @endif
                                            <td>
                                                <select class="sel_inp types">
                                                    @if(isset($v['type']) && $v['type']=='main')
                                                        <option value="main">面</option>
                                                        <option value="other">辅</option>
                                                    @elseif(isset($v['type']) && $v['type']=='other')
                                                        <option value="other">辅</option>
                                                        <option value="main">面</option>
                                                    @else
                                                        <option value="">请选择</option>
                                                        <option value="main">面</option>
                                                        <option value="other">辅</option>
                                                    @endif
                                                </select>
                                            </td>
                                            <td><input class="form_inp fabric_num rek{{$v['index']}}" type="text" abc="{{$v['cloth_id']}}" value="{{$v['fabric_num']}}"></td>
                                            <td>
                                                <select class="sel_inp colB">
                                                    <option value="">请选择</option>
                                                    @foreach($v['color_arr'] as $kk => $vv)
                                                        <option value="{{$vv['id']}}" @if($v['color']==$vv['color_name']) selected @endif >{{$vv['color_name']}}</option>
                                                    @endforeach
                                                </select>
                                            </td>
                                            <td>
                                                <select disabled class="sel_inp shuoM">
                                                    <option value=""></option>
                                                    @foreach($v['color_remark_arr'] as $kk )
                                                        <option value="{{$kk}}" @if($kk==$v['color_remark']) selected @endif>{{$kk}}</option>
                                                    @endforeach
                                                </select>
                                            </td>
                                            <td><input disabled class="form_inp xiaoL" type="text" value="{{$v['fabric_name']}}"></td>
                                            <td><input disabled class="form_inp guiGe" type="text" value="{{$v['specification']}}"></td>
                                            <td><input disabled class="form_inp Cshu" type="text" value="{{$v['purchase_need']}}"></td>
                                            <td><input class="form_inp liang shuL" type="text" value="{{$v['warehouse_need']}}"></td>
                                            <td><input class="form_inp feis danJ" type="text" value="{{$v['cost']}}"></td>

                                            <td><input disabled class="form_inp jinE" type="text" value="{{$v['cost']*$v['purchase_need']}}"></td>

                                            <td><input disabled class="form_inp feis danW" type="text" value="{{$v['unit']}}"></td>
                                            <td><a href="javascript:;" class="delOpe" @if(isset($v['id'])) abc="{{$v['id']}}" @else @endif>删除</a></td>
                                        </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="form-group"><button type='button' class='save_add btn btn-success' abc="{{$pst_infos->id}}">保存</button></div>
            </div>
        </div>
    </div>
    {{--弹框1--}}
    <div class="info_box">
        <h3 style="text-align:center;position:relative;margin-bottom:20px;"><span class="infoAdd"></span><i class="fa fa-close chaL"></i></h3>
        <div class="form-group">
            <ul class="form_ul">
                <li class="form_li" style="width:auto;">关键词：<input class="form_inp keywos" type="text" autocomplete="off" autocorrect="off" placeholder="请输入关键词" /></li>
                <button type='button' class='btn btn-info souGo'>搜索</button>
            </ul>
        </div>
        <div class="form-group">
            <table class="gong">
                <thead><tr><td style="width:350px;">供应商</td><td>供应商货号</td></tr></thead>
                <tbody></tbody>
            </table>
        </div>
        <div class="form-group">
            <div class="page1" style="width:430px;float:right;"></div>
        </div>
    </div>
    {{--弹框2--}}
    <div class="boxJxd">
        <h3 style="text-align:center;position:relative;margin-bottom:20px;"><span class="infoAdd"></span><i class="fa fa-close yinClose"></i></h3>
        <div class="container">
            {{--采购通知单选择--}}
            <div><h3>采购通知单选择</h3></div>
            <div class="form-group">
                <form>
                    <p class="seek_p">
                        <label class="seek_lab" style="width:185px;">供应商：
                            <select class="seek_sel supplier_id">
                                <option value="">请选择</option>
                                @if(count($supplier_name))
                                    @foreach($supplier_name as $k => $v)
                                    <option value="{{$v->id}}">{{$v->name}}</option>
                                    @endforeach
                                @endif
                            </select>
                        </label>
                        <label class="seek_lab">款号：<input class="seek_sel girard" type="text" autocomplete="off" autocorrect="off" placeholder="款号" name="girard" value="" /></label>
                        <button type="button" class="btn bt_del btn-info" onclick="grabble()">搜索</button>
                        <a class="btn bt_del btn-info" href="javascript:;" onclick="emptyFabric()">清空</a>
                    </p>
                </form>
            </div>
            <div class="fabric-choose">
                <span>共<span class="mate_count2">0</span>条信息</span>
                <a class="btn btn-info bt_a sureB" href="javascript:;" abc="{{$pst_infos->id}}" def="">确定</a>
            </div>
            <div class="form-group twoTb">
                <div class="fabric_div2">

                </div>
            </div>
            <span class="page2" style="float:right;"></span>
            <div style="width:100%;border-top:1px solid #ccc;float:right;height:1px;margin-top:15px;"></div>
            <div class="form-group threeTb">
                <div class="fabric_div3">

                </div>
            </div>
        </div>
    </div>
    <div class="mask" style="display:none;"></div>
{{--    <script src="{{env('CDN_DOMAIN_NAME')}}/js/storUp.js?v=1.0.2"></script>--}}
    <script>

        $.selectSuggest('colorInput0', suppliers);
        /*添加*/
        $(".addIns").click(function(){
            var b=$(".tab1 tbody").children("tr").length;
            var ary1=[];
            if(b>=1){
                for(var x=0;x<b;x++){
                    var zz1=$(".tab1 tbody").children("tr:eq("+x+")").find(".fabric_num").eq(0).attr("class");
                    var vx1=zz1.split("rek")[1];
                    ary1.push(vx1)
                }
                var maxN1 = eval("Math.max(" + ary1.toString() + ")");
                var vv1=maxN1+1;
            }else{
                var vv1=0;
            }
            var strs1='<tr class="newInfos" ids="0">'+
                '<td>'+
                '<select class="sel_inp types">'+
                '<option value="">请选择</option>'+
                '<option value="main">面</option>'+
                '<option value="other">辅</option>'+
                '</select>'+
                '</td>'+
                '<td><input class="form_inp fabric_num rek'+vv1+'" type="text" value=""></td>'+
                '<td>'+
                '<select class="sel_inp colB">'+
                '<option value="">请选择</option>'+
                '</select>'+
                '</td>'+
                '<td>'+
                '<select disabled class="sel_inp shuoM">'+
                '<option value=""></option>'+
                '</select>'+
                '</td>'+
                '<td><input disabled class="form_inp xiaoL" type="text" value=""></td>'+
                '<td><input disabled class="form_inp guiGe" type="text" value=""></td>'+
                '<td><input class="form_inp Cshu bgCshu" type="text" value=""></td>'+
                '<td><input class="form_inp liang shuL" type="text" value=""></td>'+
                '<td><input class="form_inp feis danJ" type="text" value=""></td>'+
                '<td><input disabled class="form_inp jinE" type="text" value=""></td>'+
                '<td><input disabled class="form_inp feis danW" type="text" value=""></td>'+
                '<td><a href="javascript:;" class="delOpe">删除</a></td>'+
                '</tr>';
            $(".tab1 tbody").prepend(strs1);
            setTimeout(function(){
                chunS (".feis");
                shuLiang (".liang");
                jiSuan();
            },100);
        });
        /*获取焦点显示弹框*/
        $(document).on("focus",".fabric_num",function(){
            var supplier_name=$(".supplier_name").val();
            var type=$(this).parent().siblings().children(".types").val();
            var sd=$(this).attr("class").split("rek");
            $(".gong").attr("ghf",sd[1]);
            $.ajax({
                url:'/purchase/get-supplier-fabric',
                type:'post',
                data:{
                    supplier_name:supplier_name,
                    type:type,
                    skip:1
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    $(".keywos").val('');
                    var string='';
                    if(data.success){
                        $(".gong tbody").empty();
                        var res=data.info.content;
                        for(var f in res){
                            string=string+'<tr abc='+res[f].id+'><td>'+res[f].supplier_name+'</td><td class="sales">'+res[f].fabric_num+'</td></tr>';
                        }
                        $(".gong tbody").append(string);
                        $(".gong").attr("abc","");
                        $(".gong").attr("abc",type);
                        dec(data.info.total,'page1');
                        $(".fabric_num").blur();
                        $(".mask").show();
                        $(".info_box").show();
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
        /*点击关闭*/
        $(".chaL").click(function(){
            $(".codes").blur();
            $(".info_box").hide();
            $(".mask").hide();
        });
        /*点击table弹框供应商货号*/
        $(document).on("click",".gong tbody tr",function(){
            var id=$(this).attr("abc");
            var that=this;
            $.ajax({
                url:'/purchase/fabric-infos',
                type:'post',
                data:{id:id},
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    $(".mask").hide();
                    $(".info_box").hide();
                    if(data.success){
                        var ids=$(".gong").attr("ghf");
                        $(".rek"+ids).val( $(that).children(".sales").text().trim() );
                        $(".rek"+ids).attr("abc",$(that).attr("abc"));
                        $(".rek"+ids).parent().siblings().children(".guiGe").val(data.info.specification);
                        $(".rek"+ids).parent().siblings().children(".danW").val(data.info.unit);
                        $(".rek"+ids).parent().siblings().children(".xiaoL").val(data.info.cate_name);
                        var so='';
                        for(var x in data.info.color){
                            so=so+'<option value="'+data.info.color[x].id+'">'+data.info.color[x].color_name+'</option>';
                        }
                        $(".rek"+ids).parent().siblings().children(".colB").empty();
                        $(".rek"+ids).parent().siblings().children(".colB").append('<option value="">请选择</option>'+so);

                        var sos='';
                        for(var y=0;y< data.info.color_remark.length;y++){
                            sos=sos+'<option value="'+data.info.color_remark[y]+'">'+data.info.color_remark[y]+'</option>';
                        }
                        $(".rek"+ids).parent().siblings().children(".shuoM").empty();
                        $(".rek"+ids).parent().siblings().children(".shuoM").append('<option value=""></option>'+sos);
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
        /*分页*/
        function dec(num,clas){
            $('.'+clas).createPage(function(n){
                //n即是页码，这里写你操作页面的东西
//                    console.log(n);
            },{
                pageCount:Math.ceil(Number(num)/10),//总页码,默认10
                current:1,//当前页码,默认1
                showPrev:true,//是否显示上一页按钮
                showNext:true,//是否显示下一页按钮
                showTurn:false,//是否显示跳转,默认可以
                showNear:2,//显示当前页码前多少页和后多少页，默认2
                pageSwap:true,//是否同意调剂,默认是。调剂会最大数量显示页码。例如当前页面之前无页码可以显示。则会增加之后的页码。
                showSumNum:false,//是否显示总页码
                align:'right'//对齐方式。默认右对齐。可选：left,right
            },{
                "color":"#ddd",//字体颜色
                "fontSize":14,//字体大小
                "pagesMargin":2,//每个页码或按钮之间的间隔
                "paddL":0,//左边留白
                "paddR":0,//右边留白
                "borderColor":"#ddd",//边线颜色
                "currentColor":"#ed601b",//当前页码的字体颜色
                "disableColor":"#bfbfbf",//不可点击按钮的字体颜色
                "disableBackColor":"#f2f2f2",//不可点击按钮的背景色
                "prevNextWidth":48,//上页下页的宽度
                "pagecountWidth":48,//共计多少也的宽度
                "trunWidth":110,//跳转模块宽度
                "pageWidth":(function(){})()//根据当前所有因素计算出来的最适合宽度。也可自己设定成固定值
            });
        }
        /*点击分页*/
        $(document).on("click",".tcdNumber",function () {
            if($(".rongB").parent().attr("class")=='page1'){
                var skip=$(this).text().trim();
                var supplier_name=$(".supplier_name").val();
                var type=$(".gong").attr("abc");
                cliA1(skip,supplier_name,type)
            }
        });
        $(document).on("click",".prevPage",function () {
            if($(".rongB").parent().attr("class")=='page1'){
                var skip=$(".current").text().trim();
                var supplier_name=$(".supplier_name").val();
                var type=$(".gong").attr("abc");
                cliA1(skip,supplier_name,type)
            }
        });
        $(document).on("click",".nextPage",function () {
            if($(".rongB").parent().attr("class")=='page1'){
                var skip=$(".current").text().trim();
                var supplier_name=$(".supplier_name").val();
                var type=$(".gong").attr("abc");
                cliA1(skip,supplier_name,type)
            }
        });
        function cliA1(skip,supplier_name,type){
            $.ajax({
                url:'/purchase/get-supplier-fabric',
                type:'post',
                data:{
                    supplier_name:supplier_name,
                    type:type,
                    skip:skip,
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    var string='';
                    if(data.success){
                        $(".gong tbody").empty();
                        var res=data.info.content;
                        for(var f in res){
                            string=string+'<tr abc='+res[f].id+'><td>'+res[f].supplier_name+'</td><td class="sales">'+res[f].fabric_num+'</td></tr>';
                        }
                        $(".gong tbody").append(string);
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        }
        /*搜索*/
        $(document).on("click",".souGo",function(){
            var supplier_name=$(".supplier_name").val();
            var type=$(".gong").attr("abc");
            var keywords=$(".keywos").val();
            $.ajax({
                url:'/purchase/get-supplier-fabric',
                type:'post',
                data:{
                    skip:1,
                    supplier_name:supplier_name,
                    type:type,
                    keywords:keywords
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    var string='';
                    $(".gong tbody").empty();
                    if(data.success){
                        var res=data.info.content;
                        if(res.length>0){
                            for(var f in res){
                                string=string+'<tr abc='+res[f].id+'><td>'+res[f].supplier_name+'</td><td class="sales">'+res[f].fabric_num+'</td></tr>';
                            }
                            $(".gong tbody").append(string);
                            dec(data.info.total,'page1');
                        }else{
                            $(".gong tbody").append('<tr><td colspan="2">无数据</td></tr>');
                        }
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
        /*回车搜索*/
        $('.keywos').bind('keydown',function(event){
            if(event.keyCode == "13") {
                var supplier_name=$(".supplier_name").val();
                var type=$(".gong").attr("abc");
                var keywords=$(".keywos").val();
                $.ajax({
                    url:'/purchase/get-supplier-fabric',
                    type:'post',
                    data:{
                        skip:1,
                        supplier_name:supplier_name,
                        type:type,
                        keywords:keywords
                    },
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    dataType:'json',
                    success:function(data){
                        var string='';
                        $(".gong tbody").empty();
                        if(data.success){
                            var res=data.info.content;
                            if(res.length>0){
                                for(var f in res){
                                    string=string+'<tr abc='+res[f].id+'><td>'+res[f].supplier_name+'</td><td class="sales">'+res[f].fabric_num+'</td></tr>';
                                }
                                $(".gong tbody").append(string);
                                dec(data.info.total,'page1');
                            }else{
                                $(".gong tbody").append('<tr><td colspan="2">无数据</td></tr>');
                            }


                        }else{
                            $(".faceImg").attr("src","/img/weep.png");
                            $(".oHandle").text(data.msg);
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }
                    }
                });
            }
        });
        /*删除*/
        $(document).on("click",".delOpe",function(){
            var that=this;
            var id=$(this).attr("abc");
            if(typeof(id)=="undefined"){
                $(this).parent().parent().remove();
                $(".faceImg").attr("src","/img/laugh.png");
                $(".oHandle").text("删除成功");
                $(".oSuccess").show(0).delay(1000).hide(0);
            }else{
                $.ajax({
                    url:'/purchase/notice-storage-del',
                    type:'post',
                    data:{id:id},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    dataType:'json',
                    success:function(data){
                        if(data.success){
                            $(that).parent().parent().remove();
                            $(".faceImg").attr("src","/img/laugh.png");
                            $(".oHandle").text("删除成功");
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }else{
                            $(".faceImg").attr("src","/img/weep.png");
                            $(".oHandle").text(data.msg);
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }
                    }
                });
            }
        });
        /*选择颜色*/
        $(document).on("change",".colB",function(){
            var ns=$(this).prop('selectedIndex');
            $(this).parent().siblings().children(".shuoM").prop("selectedIndex", ns);
        });
        /*保存*/
        $(".save_add").click(function(){
            var id=$(this).attr("abc");
            var notice_id=$(".yinDan").attr("abc");
            var supplier_name=$(".supplier_name").val();
            if(supplier_name==''){
                tips("请填写供应商");
                return false;
            }
            var quarter=$(".quarter").val();
            if(quarter==''){
                tips("请选择销售季节");
                return false;
            }
            var warehouse=$(".warehouse").val();
            var position=$(".place_r").val();
            var remark=$(".remark").val();
            if($(".tab1 tbody tr").length<=0){
                tips("通知单无数据，先添加数据再保存");
                return false;
            }else {
                var newsAdd='';
                var hg=$(".tab1 tbody tr").length;
                for(var kk=0;kk<hg;kk++){
                    newsAdd=newsAdd+$(".tab1 tbody tr").eq(kk).attr("ids")+',';
                }
                var notice_details_ids=newsAdd.substr(0, newsAdd.length - 1);
            }
            var types=getInfo(".types");
            if(isChong(types)==false){
                tips("类型不能为空");
                return false;
            }
            var ssh1='';
            for(var aa=0;aa<$(".fabric_num").length;aa++){
                var ssh2=$(".fabric_num").eq(aa).attr("abc");
                if(ssh2==''){
                    ssh2=0;
                }
                ssh1=ssh1+ssh2+',';
            }
            var cloth_id=ssh1.substr(0, ssh1.length - 1);
            var fabric_num=getInfo(".fabric_num");
            if(isChong(fabric_num)==false){
                tips("厂家货号不能为空");
                return false;
            }
            var colB=getInfo(".colB");
            if(isChong(colB)==false){
                tips("面辅料颜色不能为空");
                return false;
            }
            var Cshu=getInfo(".Cshu");
            if(isChong(Cshu)==false){
                tips("采购数量不能为空");
                return false;
            }
            var shuL=getInfo(".shuL");
            if(isChong(shuL)==false){
                tips("入库数量不能为空");
                return false;
            }
            var danJ=getInfo(".danJ");
            if(isChong(danJ)==false){
                tips("单价不能为空");
                return false;
            }
            $.ajax({
                url:'/purchase/notice-storage-save',
                type:'post',
                data:{
                    id:id,
                    notice_id:notice_id,
                    notice_details_ids:notice_details_ids,
                    supplier_name:supplier_name,
                    sale_quarter:quarter,
                    warehouse:warehouse,
                    position:position,
                    remark:remark,
                    fabric_type:types,
                    cloth_id:cloth_id,
                    fabric_num:fabric_num,
                    color_id:colB,
                    purchase_need:Cshu,
                    warehouse_need:shuL,
                    cost:danJ
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    if(data.success){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("保存成功");
                        $(".oSuccess").show(0).delay(800).hide(0);
                         setTimeout(function(){
                             window.location.href='/purchase/purchase-storage';
                         },800)
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
        function getInfo(id){
            var ss1='';
            for(var aa=0;aa<$(id).length;aa++){
                var ss2=$.trim($(id).eq(aa).val());
                // var ss2=$(id).eq(aa).val().trim();
                if(ss2==''){
                    ss2=0;
                }
                ss1=ss1+ss2+',';
            }
            return ss1.substr(0, ss1.length - 1);
        };
        function isChong(str){
            var arr=str.split(",");
            if(arr.indexOf('0')==-1){
                return true;
            }else{
                return false;
            }
        };
        /*tips*/
        function tips(txt){
            $(".faceImg").attr("src","/img/weep.png");
            $(".oHandle").text(txt);
            $(".oSuccess").show(0).delay(1000).hide(0);
        };
        /*费用*/
        function chunS (id){
            $(id).bind("input","onpropertychange",function(){
                $(this).val($(this).val().replace(/[^\d.]/g,""));
                $(this).val($(this).val().replace(/\.{2,}/g,"."));
                $(this).val($(this).val().replace(/^\./g,""));
                $(this).val($(this).val().replace(".","$#$").replace(/\./g,"").replace("$#$","."));
                $(this).val($(this).val().replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'));
                if($(this).val().indexOf(".")< 0 && $(this).val() !=""){
                    $(this).val(parseFloat($(this).val()));
                }
            });
        }
        chunS (".feis");
        /*数量*/
        function shuLiang (id){
            $(id).bind("input","onpropertychange",function(){
                $(this).val($(this).val().replace(/[^\d]/g,""));
            });
        }
        shuLiang (".liang");
        function jiSuan() {
            $('.danJ').bind('input propertychange', function() {
                var x1=$(this).parent("td").siblings().children(".shuL").val();
                var x2=$(this).val();
                $(this).parent("td").siblings().children(".jinE").val( accMul(x1,x2) );
            });
            $('.shuL').bind('input propertychange', function() {
                var x1=$(this).parent("td").siblings().children(".danJ").val();
                var x2=$(this).val();
                $(this).parent("td").siblings().children(".jinE").val( accMul(x1,x2) );
            });
        }
        jiSuan();
        /*有无线小数的*/
        function accMul(arg1,arg2){
            var m=0,s1=arg1.toString(),s2=arg2.toString();
            try{
                m+=s1.split(".")[1].length}catch(e){}
            try{
                m+=s2.split(".")[1].length}catch(e){}
            return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
        }

        /*弹框2*/
        /*点击引单*/
        $(document).on("click",".yinDan",function(){
            $.ajax({
                url:'/purchase/purchase-storage-quotation',
                type:'post',
                data:{skip:1},
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    $(".fabric_div2").empty();
                    $(".fabric_div3").empty();
                    if(data.success){
                        var sts1='';
                        var res=data.info.content;
                        if(res.length>0){
                            for(var f in res){
                                sts1=sts1+'<tr class="two_tr" abc='+res[f].id+'>' +
                                    '<td>'+res[f].notice_num+'</td>' +
                                    '<td>'+res[f].supplier_name+'</td>' +
                                    '<td>'+res[f].remaining_amount+'</td>' +
                                    '<td>'+res[f].server_girards+'</td>' +
                                    '<td>'+res[f].admin_person+'</td>'+
                                    '<td>'+res[f].makde_order_time+'</td>' +
                                    '<td>'+res[f].remark+'</td>' +
                                    '</tr>';
                            }
                            $(".mate_count2").text(data.info.page_count);
                            var sts2='<thead><tr><td>采购通知单号</td><td>供应商</td><td>剩余量(<span class="colr">合计:'+data.info.total.remaining_amount+'</span>)</td><td>服务款号</td><td>制单人</td><td>制单日期</td><td>备注</td></tr></thead>';
                            $(".fabric_div2").append('<table class="tab2">'+sts2+'<tbody>'+sts1+'</tbody></table>');
                            decc(data.info.page_count,'page2');
                        }else{
                            var sts2='<thead><tr><td>采购通知单号</td><td>供应商</td><td>剩余量</td><td>服务款号</td><td>制单人</td><td>制单日期</td><td>备注</td></tr></thead>';
                            $(".mate_count2").text("0");
                            $(".fabric_div2").append('<table class="tab2">'+sts2+'<tbody><tr><td colspan="7">无数据</td></tr></tbody></table>');
                        }
                        $(".mask").show();
                        $(".boxJxd").show();
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
        /*一级点击*/
        var flag=true;
        $(document).on("click",".two_tr",function(){
            $(".fabric_div3").empty();
            var id=$(this).attr("abc");
            $(this).addClass("in").siblings().removeClass("in");
            if(flag) {
                $.ajax({
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                    url: '/purchase/storage-quotation-details',
                    type: 'post',
                    data: {id: id},
                    dataType: 'json',
                    beforeSend: function () {//触发ajax请求开始时执行
                        flag = false;
                    },
                    success: function (data) {
                        if(data.success){
                            var sts3='';
                            var res=data.info.content;
                            var cos=data.info.total;
                            if(res.length>0){
                                for(var f in res){
                                    sts3=sts3+'<tr class="two_tr" def='+res[f].id+'>' +
                                        '<td>'+res[f].type+'</td>' +
                                        '<td>'+res[f].fabric_name+'</td>' +
                                        '<td>'+res[f].fabric_num+'</td>' +
                                        '<td>'+res[f].fabric_color+'</td>' +
                                        '<td>'+res[f].colors_remark+'</td>' +
                                        '<td>'+res[f].cost+'</td>' +
                                        '<td>'+res[f].fabric_sum+'</td>' +
                                        '<td>'+res[f].price_sum+'</td>' +
                                        '<td>'+res[f].unit+'</td>' +
                                        '<td>'+res[f].specification+'</td>' +
                                        '</tr>';
                                }
                                var sts4='<thead><tr><td>类型</td><td>小类</td><td>厂家货号</td><td>颜色</td><td>颜色说明</td><td>单价</td><td>数量(<span class="colr">合计:'+cos.total_fabric+'</span>)</td><td>金额(<span class="colr">合计:'+cos.total_price+'元</span>)</td><td>单位</td><td>面辅料规格</td></tr></thead>';
                                $(".fabric_div3").append('<table class="tab3">'+sts4+'<tbody>'+sts3+'</tbody></table>');
                            }else{
                                var sts4='<thead><tr><td>类型</td><td>小类</td><td>厂家货号</td><td>颜色</td><td>颜色说明</td><td>单价</td><td>数量</td><td>金额</td><td>单位</td><td>面辅料规格</td></tr></thead>';
                                $(".fabric_div3").append('<table class="tab3">'+sts4+'<tbody><tr><td colspan="10">无数据</td></tr></tbody></table>');
                            }
                        }else{
                            $(".faceImg").attr("src","/img/weep.png");
                            $(".oHandle").text(data.msg);
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }
                    },
                    complete: function () {//ajax请求完成时执行
                        flag = true;
                    }
                });
            }
        });
        /*清空*/
        function emptyFabric(){
            $(".seek_sel").each(function(){
                $(this).val("");
            })
        }
        /*搜索*/
        function grabble(){
            var supplier_id=$(".supplier_id").val();
            var girard=$(".girard").val();
            $.ajax({
                url:'/purchase/purchase-storage-quotation',
                type:'post',
                data:{
                    skip:1,
                    supplier_id:supplier_id,
                    girard:girard
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    $(".fabric_div2").empty();
                    $(".fabric_div3").empty();
                    if(data.success){
                        var sts1='';
                        var res=data.info.content;
                        if(res.length>0){
                            for(var f in res){
                                sts1=sts1+'<tr class="two_tr" abc='+res[f].id+'>' +
                                    '<td>'+res[f].notice_num+'</td>' +
                                    '<td>'+res[f].supplier_name+'</td>' +
                                    '<td>'+res[f].remaining_amount+'</td>' +
                                    '<td>'+res[f].server_girards+'</td>' +
                                    '<td>'+res[f].admin_person+'</td>'+
                                    '<td>'+res[f].makde_order_time+'</td>' +
                                    '<td>'+res[f].remark+'</td>' +
                                    '</tr>';
                            }
                            $(".mate_count2").text(data.info.page_count);
                            var sts2='<thead><tr><td>采购通知单号</td><td>供应商</td><td>剩余量(<span class="colr">合计:'+data.info.total.remaining_amount+'</span>)</td><td>服务款号</td><td>制单人</td><td>制单日期</td><td>备注</td></tr></thead>';
                            $(".fabric_div2").append('<table class="tab2">'+sts2+'<tbody>'+sts1+'</tbody></table>');
                            decc(data.info.page_count,'page2');
                        }else{
                            var sts2='<thead><tr><td>采购通知单号</td><td>供应商</td><td>剩余量</td><td>服务款号</td><td>制单人</td><td>制单日期</td><td>备注</td></tr></thead>';
                            $(".mate_count2").text("0");
                            $(".fabric_div2").append('<table class="tab2">'+sts2+'<tbody><tr><td colspan="7">无数据</td></tr></tbody></table>');
                        }
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        };
        /*分页*/
        function decc(num,clas){
            $('.'+clas).createPage(function(n){
                //n即是页码，这里写你操作页面的东西
//                    console.log(n);
            },{
                pageCount:Math.ceil(Number(num)/5),//总页码,默认10
                current:1,//当前页码,默认1
                showPrev:true,//是否显示上一页按钮
                showNext:true,//是否显示下一页按钮
                showTurn:false,//是否显示跳转,默认可以
                showNear:2,//显示当前页码前多少页和后多少页，默认2
                pageSwap:true,//是否同意调剂,默认是。调剂会最大数量显示页码。例如当前页面之前无页码可以显示。则会增加之后的页码。
                showSumNum:false,//是否显示总页码
                align:'right'//对齐方式。默认右对齐。可选：left,right
            },{
                "color":"#ddd",//字体颜色
                "fontSize":14,//字体大小
                "pagesMargin":2,//每个页码或按钮之间的间隔
                "paddL":0,//左边留白
                "paddR":0,//右边留白
                "borderColor":"#ddd",//边线颜色
                "currentColor":"#ed601b",//当前页码的字体颜色
                "disableColor":"#bfbfbf",//不可点击按钮的字体颜色
                "disableBackColor":"#f2f2f2",//不可点击按钮的背景色
                "prevNextWidth":48,//上页下页的宽度
                "pagecountWidth":48,//共计多少也的宽度
                "trunWidth":110,//跳转模块宽度
                "pageWidth":(function(){})()//根据当前所有因素计算出来的最适合宽度。也可自己设定成固定值
            });
        };
        /*点击分页*/
        $(document).on("click",".tcdNumber",function () {
            if($(".rongB").parent().attr("class")=='page2'){
                var skip=$(this).text().trim();
                var supplier_id=$(".supplier_id").val();
                var girard=$(".girard").val();
                cliA2(skip,supplier_id,girard)
            }
        });
        $(document).on("click",".prevPage",function () {
            if($(".rongB").parent().attr("class")=='page2'){
                var skip=$(".current").text().trim();
                var supplier_id=$(".supplier_id").val();
                var girard=$(".girard").val();
                cliA2(skip,supplier_id,girard)
            }
        });
        $(document).on("click",".nextPage",function () {
            if($(".rongB").parent().attr("class")=='page2'){
                var skip=$(".current").text().trim();
                var supplier_id=$(".supplier_id").val();
                var girard=$(".girard").val();
                cliA2(skip,supplier_id,girard)
            }
        });
        /*跳转分页*/
        function cliA2(skip,supplier_id,girard){
            $.ajax({
                url:'/purchase/purchase-storage-quotation',
                type:'post',
                data:{
                    skip:skip,
                    supplier_id:supplier_id,
                    girard:girard
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    $(".fabric_div2").empty();
                    $(".fabric_div3").empty();
                    if(data.success){
                        var sts1='';
                        var res=data.info.content;
                        if(res.length>0){
                            for(var f in res){
                                sts1=sts1+'<tr class="two_tr" abc='+res[f].id+'>' +
                                    '<td>'+res[f].notice_num+'</td>' +
                                    '<td>'+res[f].supplier_name+'</td>' +
                                    '<td>'+res[f].remaining_amount+'</td>' +
                                    '<td>'+res[f].server_girards+'</td>' +
                                    '<td>'+res[f].admin_person+'</td>'+
                                    '<td>'+res[f].makde_order_time+'</td>' +
                                    '<td>'+res[f].remark+'</td>' +
                                    '</tr>';
                            }
                            $(".mate_count2").text(data.info.page_count);
                            var sts2='<thead><tr><td>采购通知单号</td><td>供应商</td><td>剩余量(<span class="colr">合计:'+data.info.total.remaining_amount+'</span>)</td><td>服务款号</td><td>制单人</td><td>制单日期</td><td>备注</td></tr></thead>';
                            $(".fabric_div2").append('<table class="tab2">'+sts2+'<tbody>'+sts1+'</tbody></table>');
                        }else{
                            var sts2='<thead><tr><td>采购通知单号</td><td>供应商</td><td>剩余量</td><td>服务款号</td><td>制单人</td><td>制单日期</td><td>备注</td></tr></thead>';
                            $(".mate_count2").text("0");
                            $(".fabric_div2").append('<table class="tab2">'+sts2+'<tbody><tr><td colspan="7">无数据</td></tr></tbody></table>');
                        }
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        }
        /*点击关闭*/
        $(".yinClose").click(function(){
            $(".boxJxd").hide();
            $(".mask").hide();
        });
        /*点击确定*/
        $(".sureB").click(function(){
            var id=$(".two_tr.in").attr("abc");
            if(id==undefined){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("先选择一条信息再确定");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            $.ajax({
                url:'/purchase/confirm-notice-storage',
                type:'post',
                data:{id:id},
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    if(data.success){
                        $('.tab1 tbody').empty();
                        $(".mask").hide();
                        $(".boxJxd").hide();
                        $(".yinDan").attr("abc",id);
                        var das=data.info.content;
                        var res=data.info.fabric;
                        $(".supplier_name").val(das.supplier_name);
                        $(".quarter").val(das.sale_quarter);
                        $(".warehouse").val(das.warehouse);
                        $(".place_r").val(das.server_girards);
                        $(".remark").val(das.remark);
                        if(res.length>0){
                            for(var j in res){
                                var coarr=res[j].color_arr;
                                var op1='';
                                for(var c1=0;c1<coarr.length;c1++){
                                    op1=op1+'<option value='+coarr[c1].id+'>'+coarr[c1].color_name+'</option>';
                                }
                                var sharr=res[j].color_remark_arr;
                                var op2='';
                                for(var c2=0;c2<sharr.length;c2++){
                                    op2=op2+'<option value='+sharr[c2]+'>'+sharr[c2]+'</option>';
                                }
                                var strs1='<tr class=tr'+res[j].id+' ids='+res[j].id+'>'+
                                    '<td>'+
                                    '<select class="sel_inp types">'+
                                    '<option value="">请选择</option>'+
                                    '<option value="main">面</option>'+
                                    '<option value="other">辅</option>'+
                                    '</select>'+
                                    '</td>'+
                                    '<td><input class="form_inp fabric_num rek'+res[j].loop+'" type="text" value='+res[j].fabric_num+' abc='+res[j].cloth_id+'></td>'+
                                    '<td>'+
                                    '<select class="sel_inp colB">'+
                                    '<option value="">请选择</option>'+
                                    ''+op1+''+
                                    '</select>'+
                                    '</td>'+
                                    '<td>'+
                                    '<select disabled class="sel_inp shuoM">'+
                                    '<option value=""></option>'+
                                    ''+op2+''+
                                    '</select>'+
                                    '</td>'+
                                    '<td><input disabled class="form_inp xiaoL" type="text" value='+res[j].fabric_name+'></td>'+
                                    '<td><input disabled class="form_inp guiGe" type="text" value='+res[j].specification+'></td>'+

                                    '<td><input disabled class="form_inp Cshu" type="text" value='+res[j].purchase_need+'></td>'+
                                    '<td><input class="form_inp liang shuL" type="text" value='+res[j].warehouse_need+'></td>'+

                                    '<td><input class="form_inp feis danJ" type="text" value='+res[j].cost+'></td>'+
                                    '<td><input disabled class="form_inp jinE" type="text" value='+Number(res[j].cost)*Number(res[j].warehouse_need)+'></td>'+
                                    '<td><input disabled class="form_inp feis danW" type="text" value='+res[j].unit+'></td>'+
                                    '<td><a href="javascript:;" class="delOpe" abc='+res[j].id+'>删除</a></td>'+
                                    '</tr>';
                                $('.tab1 tbody').append(strs1);
                                $(".tr"+res[j].id).children("td").children(".types").val(res[j].type);
                                $(".tr"+res[j].id).children("td").children(".colB").val(res[j].color_id);
                                $(".tr"+res[j].id).children("td").children(".shuoM").val(res[j].color_remark);
                                setTimeout(function(){
                                    chunS (".feis");
                                    shuLiang (".liang");
                                    jiSuan();
                                },100);
                            }
                        }else{

                        }
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
    </script>
@endsection